#ifndef  __EVENTCONTROLLER_H__
#define  __EVENTCONTROLLER_H__

// boost
#include <boost/noncopyable.hpp>
#include <boost/variant.hpp>

// std
#include <map>
#include <list>
#include <string>

// seq
#include "EventHandler.h"
#include "Event.h"

namespace seq {

class EventType {
public:
    EventType() : eventType_(0), id_(0) {}
    EventType(int eventT) : eventType_(eventT), id_(0) {}
    EventType(int eventT, int id) : eventType_(eventT), id_(id) {}
    int eventType() const {return eventType_;}
    int id() const {return id_;}
private:
    int eventType_;
    int id_;
};

bool operator== (const EventType& lhs, const EventType& rhs);
bool operator!= (const EventType& lhs, const EventType& rhs);
bool operator< (const EventType& lhs, const EventType& rhs);
bool operator> (const EventType& lhs, const EventType& rhs);
bool operator<= (const EventType& lhs, const EventType& rhs);
bool operator>= (const EventType& lhs, const EventType& rhs);

class EventController : boost::noncopyable {
public:
    // return id
    int addEventHandle(const EventType& eventType, const EventHandlerPtr& handler);
    int addEventHandle(const EventType& eventType, EventHandler* handler);
    void delEventHandle(const EventType& eventType, int id);
    // delete all target event-handle
    void delEventHandle(const EventType& eventType);
    // delete all event-handle
    void clear();
    void fire(const EventType& eventType, boost::any event);
    void fire(const EventType& eventType);
private:
    typedef std::list<EventHandlerPtr>        EventHandlerMapVal; 
    typedef std::map<EventType, EventHandlerMapVal> EventHandlerMap;    
    typedef EventHandlerMap::iterator         iterator;           

    EventHandlerMap handlers_;          
    static int nextID_;            
};

extern EventController g_ectl;

} // end of namespace seq

#endif   /* ----- #ifndef __EVENTCONTROLLER_H__  ----- */
